package com.youlai.boot.system.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.common.util.WeChatDecryptUtil;
import com.youlai.boot.system.model.bo.DecryptBO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制层
 *
 * @author Ray
 * @since 2022/10/16
 */
@RestController
@RequestMapping("/api/v1/decrypt")
@RequiredArgsConstructor
public class DecryptController {

    @PostMapping
    public Result<JSONObject> decrypt(@RequestBody DecryptBO decryptBO) {
        try {
            String res = WeChatDecryptUtil.decryptData(decryptBO.getSessionKey(), decryptBO.getEncryptedData(), decryptBO.getIv());
            return Result.success(JSONUtil.parseObj(res));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
